<?php

class Subcategory extends AppModel {

  var $name = "Subcategory";
  
  var $primaryKey = 'subcategory_id';
  
  var $belongsTo = array("Category");
  
  var $hasMany = array(
    "Product" => array(
      "conditions" => "Product.donotlist = '0'",
      "order" => "Product.product_name"
    )
  );
  
  function optionsArray() {
    $cats = $this->findAll(null, null, 'Category.category_name ASC, Subcategory.subcategory_name ASC');
    $ret = array();
    foreach($cats as $sub) {
      $ret[$sub['Subcategory']['subcategory_id']] = $sub['Category']['category_name'] . ": " . $sub['Subcategory']['subcategory_name'];
    }
    return $ret;
  }

}
